package promote.brozen.reactor;

import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

import java.util.Scanner;
import java.util.concurrent.locks.LockSupport;

/**
 * @author Brozen
 * @date 2020/6/29 8:38 AM
 * @email brozen@qq.com
 */
public class FluxPublisher {

    public static void main(String[] args) {
        Flux.from(new BPublisher())
                .subscribeOn(Schedulers.elastic())
                .subscribe(System.out::println);

        LockSupport.park();
    }



    static class BPublisher implements Publisher<String> {

        @Override
        public void subscribe(Subscriber<? super String> subscriber) {
            subscriber.onNext("start");

            Scanner scanner = new Scanner(System.in);
            String msg = scanner.nextLine();
            while (!"exit".equals(msg)) {
                subscriber.onNext(msg);
                msg = scanner.nextLine();
            }
        }

    }


}
